package bigraph.figure;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FlowLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.RoundedRectangle;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.*;
import org.eclipse.swt.SWT;

public class RootFigure extends Figure {

	public static final int ROOT_FIGURE_DEFWIDTH = 200;
	public static final int ROOT_FIGURE_DEFHEIGHT = 300;
	
	private Label labelRootNumber = new Label();
	private XYLayout layout;
	Figure container;
	RoundedRectangle shape;
	
	public RootFigure() {
		container = new Figure();
		container.setLayoutManager(new XYLayout());
		layout = new XYLayout();
        setLayoutManager(layout);
        add(container);
      //  setConstraint(container, new Rectangle(0,0,-1,-1));
        labelRootNumber.setForegroundColor(ColorConstants.gray);
		labelRootNumber.setBounds(new Rectangle(10,10,50,20));
		labelRootNumber.setLabelAlignment(PositionConstants.LEFT);
		container.add(labelRootNumber,-1);
	//	container.setConstraint(labelRootNumber, new Rectangle (10,10,-1,-1));
		
		shape = new RoundedRectangle();
		shape.setBounds(container.getBounds());
		container.add(shape);
		//container.setConstraint(shape, new Rectangle(0,0,-1,-1));
		shape.setCornerDimensions(new Dimension(30,30));
		shape.setLineStyle(SWT.LINE_DASH);
		shape.setLineWidth(3);
		shape.setFill(false);
		shape.setAlpha(40);
		container.setOpaque(false);
		setOpaque(false);
   }
	
    public void setName(String text) {
        labelRootNumber.setText(text);
   }

    public void setLayout(Rectangle rect) {
		if(getParent()==null) {
			this.setBounds(rect);
			container.setBounds(rect);
			shape.setBounds(rect);
		}
		else {
			Point point = getParent().getBounds().getLocation();
			Rectangle childRec = new Rectangle(point.x + rect.x, point.y + rect.y, rect.width, rect.height);
			this.setBounds(childRec);
			container.setBounds(childRec);
			shape.setBounds(childRec);
		}
    //	getParent().setConstraint(this, rect);
   // 	this.setConstraint(container, rect);
    //	container.setConstraint(shape, rect);
    	
   }
    
    @Override
    public void add(IFigure figure, Object constraint, int index) {
    	// TODO Auto-generated method stub
    	super.add(figure, constraint, -1);
    }

}
